package br.iars.model.entity;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="preference")
@AttributeOverride(name = "id", column = @Column(name = "preference_id"))
public class Preference extends GenericEntity<Long> implements
		org.apache.mahout.cf.taste.model.Preference {

	private static final long serialVersionUID = 1257383067523977993L;

	@ManyToOne
	@JoinColumn(name = "user_id")
	private User user;

	@ManyToOne
	@JoinColumn(name = "item_id")
	private Item item;

	@Column(name = "rate", nullable = false)
	private Float rate;

	public Preference() {
		super();
	}

	public Preference(Long id) {
		super(id);
	}

	public Preference(User user, Item item, Float rate) {
		super();
		this.user = user;
		this.item = item;
		this.rate = rate;
	}

	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public Float getRate() {
		return rate;
	}

	public void setRate(Float rate) {
		this.rate = rate;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String toString() {
		return "Preference [item=" + item + ", rate=" + rate + ", user=" + user
				+ "]";
	}

	@Transient
	public long getUserID() {
		return this.user.getId();
	}

	@Transient
	public long getItemID() {
		return this.item.getId();
	}

	@Transient
	public float getValue() {
		return this.getRate();
	}

	public void setValue(float value) {
		setRate(value);
	}

}
